• MGLStyleLayer is an abstract base class for style layers. A style layer manages the layout and appearance of content at a specific z-index in a style. An MGLStyle object consists of one or more MGLStyleLayer objects.

    Each style layer defined by the style JSON file is represented at runtime by an MGLStyleLayer object, which you can use to refine the map’s appearance. You can also add and remove style layers dynamically.

    Create instances of MGLBackgroundStyleLayer and the concrete subclasses of MGLForegroundStyleLayer in order to use MGLStyleLayer‘s properties and methods. You do not create instances of MGLStyleLayer directly, and do not create your own subclasses of this class.

    Do not add MGLStyleLayer objects to the style property of a MGLMapView before -mapView:didFinishLoadingStyle: is called.

    See more

    Declaration

    Objective-C

    
    @interface MGLStyleLayer : NSObject

    Swift

    class MGLStyleLayer : NSObject
  • An MGLBackgroundStyleLayer is a style layer that covers the entire map. Use a background style layer to configure a color or pattern to show below all other map content. If the style’s other layers use the Mapbox Streets source, the background style layer is responsible for drawing land, whereas the oceans and other bodies of water are drawn by MGLFillStyleLayer objects.

    A background style layer is typically the bottommost layer in a style, because it covers the entire map and can occlude any layers below it. You can therefore access it by getting the last item in the MGLStyle.layers array.

    If the background style layer is transparent or omitted from the style, any portion of the map view that does not show another style layer is transparent.

    See more

    Declaration

    Objective-C

    
    @interface MGLBackgroundStyleLayer : MGLStyleLayer

    Swift

    class MGLBackgroundStyleLayer : MGLStyleLayer
  • An MGLRasterStyleLayer is a style layer that renders georeferenced raster imagery on the map, especially raster tiles.

    Use a raster style layer to configure the color parameters of raster tiles loaded by an MGLRasterTileSource object or raster images loaded by an MGLImageSource object. For example, you could use a raster style layer to render Mapbox Satellite imagery, a raster tile set uploaded to Mapbox Studio, or a raster map authored in TileMill, the classic Mapbox Editor, or Mapbox Studio Classic.

    Raster images may also be used as icons or patterns in a style layer. To register an image for use as an icon or pattern, use the -[MGLStyle setImage:forName:] method. To configure a point annotation’s image, use the MGLAnnotationImage class.

    You can access an existing raster style layer using the -[MGLStyle layerWithIdentifier:] method if you know its identifier; otherwise, find it using the MGLStyle.layers property. You can also create a new raster style layer and add it to the style using a method such as -[MGLStyle addLayer:].

    See the Add an image and Add raster imagery examples to learn how to add imagery with this style layer.

    Example

    let layer = MGLRasterStyleLayer(identifier: "clouds", source: source)
    layer.rasterOpacity = NSExpression(forConstantValue: 0.5)
    mapView.style?.addLayer(layer)
    
    See more

    Declaration

    Objective-C

    
    @interface MGLRasterStyleLayer : MGLForegroundStyleLayer

    Swift

    class MGLRasterStyleLayer : MGLForegroundStyleLayer
  • An MGLSymbolStyleLayer is a style layer that renders icon and text labels at points or along lines on the map.

    Use a symbol style layer to configure the visual appearance of feature labels. These features can come from vector tiles loaded by an MGLVectorTileSource object, or they can be MGLShape or MGLFeature instances in an MGLShapeSource or MGLComputedShapeSource object.

    You can access an existing symbol style layer using the -[MGLStyle layerWithIdentifier:] method if you know its identifier; otherwise, find it using the MGLStyle.layers property. You can also create a new symbol style layer and add it to the style using a method such as -[MGLStyle addLayer:].

    See the Dynamically style interactive points and Use images to cluster point data examples learn how to style data on your map using this layer.

    Example

    let layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois)
    layer.sourceLayerIdentifier = "pois"
    layer.iconImageName = NSExpression(forConstantValue: "coffee")
    layer.iconScale = NSExpression(forConstantValue: 0.5)
    layer.text = NSExpression(forKeyPath: "name")
    layer.textTranslation = NSExpression(forConstantValue: NSValue(cgVector: CGVector(dx: 10, dy: 0)))
    layer.textJustification = NSExpression(forConstantValue: "left")
    layer.textAnchor = NSExpression(forConstantValue: "left")
    layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee")
    mapView.style?.addLayer(layer)
    
    See more

    Declaration

    Objective-C

    
    @interface MGLSymbolStyleLayer : MGLVectorStyleLayer

    Swift

    class MGLSymbolStyleLayer : MGLVectorStyleLayer